package com.mrd.gtimp.business.entity;

import com.mrd.annotation.validation.InDeclarationRequiredGroup;
import com.mrd.annotation.validation.MRDLength;
import com.mrd.annotation.validation.OutDeclarationRequiredGroup;
import com.mrd.gtimp.base.entity.Company;
import com.mrd.gtimp.base.entity.User;

import org.hibernate.annotations.GenericGenerator;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * <p>
 * application name: sample
 * <p>
 * copyright: Copyright@2012 明睿达科技有限公司 业务信息基础类，抽象出公共信息
 * 
 * @author winaya 业务信息基础类，抽象出公共信息
 * @author winaya 业务信息基础类，抽象出公共信息
 * @author winaya 业务信息基础类，抽象出公共信息
 * @author winaya 业务信息基础类，抽象出公共信息
 * @author winaya 业务信息基础类，抽象出公共信息
 * @author winaya 业务信息基础类，抽象出公共信息
 * @author winaya 业务信息基础类，抽象出公共信息
 * @author winaya 业务信息基础类，抽象出公共信息
 * @author winaya 业务信息基础类，抽象出公共信息
 * @author winaya 业务信息基础类，抽象出公共信息
 * @author winaya 业务信息基础类，抽象出公共信息
 * @author winaya 业务信息基础类，抽象出公共信息
 * @author winaya 业务信息基础类，抽象出公共信息
 * @author winaya 业务信息基础类，抽象出公共信息
 * @author winaya
 */
/**
 * 业务信息基础类，抽象出公共信息
 * 
 * @author winaya
 */

/**
 * @author luob
 */
@Entity(name = "T_BIZ_BASE_BUSINESS")
@Inheritance(strategy = InheritanceType.JOINED)
@org.hibernate.annotations.Entity(dynamicUpdate = true)
public abstract class BaseBusiness {

  @Id
  @GeneratedValue(generator = "paymentableGenerator")
  @GenericGenerator(name = "paymentableGenerator", strategy = "uuid")
  @Column(name = "ID")
  @MRDLength(max = 32)
  private String id;

  /**
   * 发货人（经营单位）,真实托运人，从客户联系人列表获取
   */
  @ManyToOne
  @JoinColumn(name = "REAL_CUSTOMER_ID")
  @Valid
  private Contacter shipper;

  /**
   * 下单的客户公司/代理公司
   */
  @ManyToOne
  @JoinColumn(name = "CUSTOMER_COM_ID", updatable = false)
  private Company customer;

  @Column(name = "CREATOR", updatable = false)
  private String creator;

  @Column(name = "CTIME", updatable = false)
  private Date ctime;

  @Column(name = "MODIFIER")
  private String modifier;

  @Column(name = "MTIME")
  private Date mtime;

  @Column(name = "BUSINESS_ID", updatable = false)
  private String businessId;

  @Column(name = "TYPE", updatable = false)
  private String type;

  /**
   * 业务供应商/业务代理人（报关公司）
   */
  @ManyToOne
  @JoinColumn(name = "SUP_ID")
  @Valid
  @NotNull(groups = {InDeclarationRequiredGroup.class, OutDeclarationRequiredGroup.class},
      message = "报关行[此项不能留空]")
  private Company supCompany;

  @Column(name = "R_SUP_ID")
  private String realSupId;

  /**
   * 业务系统主键信息，多主键用'-'间隔表示，次内容在客户下单后，业务数据提交到业务系统后，业务系统反馈会该键，如果该键不存在则下单不成功
   */
  @Column(name = "BPK")
  private String bpk;

  /**
   * 业务确认时间、下单时间
   */
  @Column(name = "CONFIRM_TIME")
  private Date confirmTime;
  /**
   * 业务审核通过时间
   */
  @Column(name = "VALIDATE_TIME")
  private Date validateTime;
  /**
   * 保留
   */
  // @Transient
  // private Date VALIDATE_TIME;

  /**
   * 业务审核员信息拓展，若VALIDATE_ID字段为空，则填写该字段，可用于外部审核
   */
  @Column(name = "VALIDATOR_EXT")
  private String validator_ext;

  /**
   * 业务审核员
   */
  @ManyToOne
  @JoinColumn(name = "VALIDATOR_ID")
  private User validator;
  /**
   * 业务上传通过时间
   */
  @Column(name = "UPLOAD_TIME")
  private Date upload_time;

  /**
   * 业务上传员信息拓展，若UPLOADER_ID字段为空，则填写该字段，可用于外部上传
   */
  @Column(name = "UPLOADER_EXT")
  private String uploader_ext;

  /**
   * 业务上传员
   */
  @ManyToOne
  @JoinColumn(name = "UPLOADER_ID")
  private User uploader;
  /**
   * 业务上传通过时间
   */
  @Column(name = "FINISH_TIME")
  private Date finish_time;

  /**
   * 业务上传员信息拓展，若FINISHER_ID字段为空，则填写该字段，可用于外部上传
   */
  @Column(name = "FINISHER_EXT")
  private String finisher_ext;

  /**
   * 业务上传员
   */
  @ManyToOne
  @JoinColumn(name = "FINISHER_ID")
  private User finisher;

  @OneToMany(mappedBy = "declaration", cascade = CascadeType.ALL)
  private List<RejectContent> rejectContents;

  /**
   * 是否通关一体化
   */
  @MRDLength(max = 1, name = "是否通关一体化")
  @Column(name = "is_tongguan_yth")
  @Valid
  @NotNull(groups = {InDeclarationRequiredGroup.class, OutDeclarationRequiredGroup.class},
          message = "是否通关一体化[此项不能留空]")
  private String isTongguanYth = "0";

  /**
   * 第二供应商
   */
  @MRDLength(max = 32, name = "第二供应商")
  @Column(name = "second_sup_id")
  private String secondSupId;

  /**
   * 第二供应商
   */
  @MRDLength(max = 32, name = "第二供应商")
  @Column(name = "second_sup_id_code")
  private String secondSupIdCode;

  // ---qp tools--//
  @Column(name = "QPDRSJ")
  private Date qpdrsj;
  @Column(name = "QPSCSJ")
  private Date qpscsj;
  @Column(name = "QP_DJZT")
  private String qpdjzt;
  /**
   * QP统一编码
   */
  @Column(name = "QP_TYNO")
  private String qptyno;

  @Column(name = "AGENT_FOR_COM_ID")
  private String agent_for_com_id;
  @Column(name="ENTER_TYPE")
  private String enter_type;

  @Column(name="ENTER_PAGE")
  private String enter_page;
  @Column(name = "AGENT_NAME")
  private String agent_name;

  public void setAgent_name(String agent_name) {
    this.agent_name = agent_name;
  }

  public String getAgent_name() {
    return agent_name;
  }

  public void setAgent_for_com_id(String agent_for_com_id) {
    this.agent_for_com_id = agent_for_com_id;
  }

  public String getAgent_for_com_id() {
    return agent_for_com_id;
  }

  public void setEnter_type(String enter_type) {
    this.enter_type = enter_type;
  }

  public String getEnter_type() {
    return enter_type;
  }

  public String getEnter_page() {
    return enter_page;
  }

  public void setEnter_page(String enter_page) {
    this.enter_page = enter_page;
  }

  public String getCreator() {
    return creator;
  }

  public void setCreator(String creator) {
    this.creator = creator;
  }

  public Date getCtime() {
    return ctime;
  }

  public void setCtime(Date ctime) {
    this.ctime = ctime;
  }

  public String getModifier() {
    return modifier;
  }

  public void setModifier(String modifier) {
    this.modifier = modifier;
  }

  public Date getMtime() {
    return mtime;
  }

  public void setMtime(Date mtime) {
    this.mtime = mtime;
  }

  public Contacter getShipper() {
    return shipper;
  }

  public void setShipper(Contacter shipper) {
    this.shipper = shipper;
  }

  public abstract BaseBusiness fromString(String businessString);

  @Override
  public abstract String toString();

  public Company getCustomer() {
    return customer;
  }

  public void setCustomer(Company customer) {
    this.customer = customer;
  }

  public String getId() {
    return id;
  }

  public void setId(String id) {
    this.id = id;
  }

  public String getBusinessId() {
    return businessId;
  }

  public void setBusinessId(String businessId) {
    this.businessId = businessId;
  }

  public String getType() {
    return type;
  }

  public void setType(String type) {
    this.type = type;
  }

  public Company getSupCompany() {
    return supCompany;
  }

  public void setSupCompany(Company supCompany) {
    this.supCompany = supCompany;
  }

  public String getBpk() {
    return bpk;
  }

  public void setBpk(String bpk) {
    this.bpk = bpk;
  }

  public Date getUpload_time() {
    return upload_time;
  }

  public void setUpload_time(Date upload_time) {
    this.upload_time = upload_time;
  }

  public String getUploader_ext() {
    return uploader_ext;
  }

  public void setUploader_ext(String uploader_ext) {
    this.uploader_ext = uploader_ext;
  }

  public User getUploader() {
    return uploader;
  }

  public void setUploader(User uploader) {
    this.uploader = uploader;
  }

  public User getValidator() {
    return validator;
  }

  public void setValidator(User validator) {
    this.validator = validator;
  }

  public String getValidator_ext() {
    return validator_ext;
  }

  public void setValidator_ext(String validator_ext) {
    this.validator_ext = validator_ext;
  }

  public Date getFinish_time() {
    return finish_time;
  }

  public void setFinish_time(Date finish_time) {
    this.finish_time = finish_time;
  }

  public String getFinisher_ext() {
    return finisher_ext;
  }

  public void setFinisher_ext(String finisher_ext) {
    this.finisher_ext = finisher_ext;
  }

  public User getFinisher() {
    return finisher;
  }

  public void setFinisher(User finisher) {
    this.finisher = finisher;
  }

  /**
   * 清除自身业务数据主键的工具方法
   */
  public abstract void clearPk() throws Exception;

  public String getRealSupId() {
    return realSupId;
  }

  public void setRealSupId(String realSupId) {
    this.realSupId = realSupId;
  }

  public List<RejectContent> getRejectContents() {
    return rejectContents;
  }

  public void setRejectContents(List<RejectContent> rejectContents) {
    this.rejectContents = rejectContents;
  }

  public Date getValidateTime() {
    return validateTime;
  }

  public void setValidateTime(Date validateTime) {
    this.validateTime = validateTime;
  }

  public Date getVALIDATE_TIME() {
    return validateTime;
  }

  public Date getQpdrsj() {
    return qpdrsj;
  }

  public void setQpdrsj(Date qpdrsj) {
    this.qpdrsj = qpdrsj;
  }

  public Date getQpscsj() {
    return qpscsj;
  }

  public void setQpscsj(Date qpscsj) {
    this.qpscsj = qpscsj;
  }

  public String getQpdjzt() {
    return qpdjzt;
  }

  public void setQpdjzt(String qpdjzt) {
    this.qpdjzt = qpdjzt;
  }

  public String getQptyno() {
    return qptyno;
  }

  public void setQptyno(String qptyno) {
    this.qptyno = qptyno;
  }

  public Date getConfirmTime() {
    return confirmTime;
  }

  public void setConfirmTime(Date confirmTime) {
    this.confirmTime = confirmTime;
  }

  public String getIsTongguanYth() {
    return isTongguanYth;
  }

  public void setIsTongguanYth(String isTongguanYth) {
    this.isTongguanYth = isTongguanYth;
  }

  public String getSecondSupId() {
    return secondSupId;
  }

  public void setSecondSupId(String secondSupId) {
    this.secondSupId = secondSupId;
  }

  public String getSecondSupIdCode() {
    return secondSupIdCode;
  }

  public void setSecondSupIdCode(String secondSupIdCode) {
    this.secondSupIdCode = secondSupIdCode;
  }

}
